package com.ruoyi.web.controller.api;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Activity;
import com.ruoyi.system.service.IActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
@RequestMapping("/api")
@RestController
public class wxActivityController {
    @Autowired
    IActivityService activityService;
    @RequestMapping("/activityList")
    public AjaxResult showActivity(@RequestParam String actDate){
        Activity activity =new Activity();
        List<Activity> activityList = activityService.selectActivityList(activity);
        System.out.println(activityList);
        List<Activity> actList = new ArrayList<>();
        for(int i =0;i<activityList.size();i++){
            if (activityList.get(i).getActDate().contains(actDate)){
                actList.add(activityList.get(i));
            }
        }
        if(actList.isEmpty()){
            return AjaxResult.error();
        }else{
            return AjaxResult.success(actList);
        }
    }
    @RequestMapping("/activityById")
    public AjaxResult showActivityById(@RequestParam Integer actId){
        Activity activity = activityService.selectActivityByActId(Long.valueOf(actId));
        return AjaxResult.success(activity);
    }




}
